#include "QPushButton"
#include "QLabel"
#include <qfont.h>
#include "game.h"
#include "mainwindow.h"
#include "dialog.h"

dialog::dialog(QString str, int length, int width, int number, int time) {
    this->setFixedSize(800, 400);
    this->len = length;
    this->wid = width;
    this->num = number;
    QFont font;
    font.setPointSize(20);
    QLabel *result = new QLabel(str, this);
    result->setFont(font);
    result->move(150, 110);
    result->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
    //-----如果游戏胜利，显示时间-----
    if (time != -1) {
        font.setPointSize(15);
        QLabel *time_label = new QLabel(QString::number(time), this);
        QLabel *text_time = new QLabel("使用时间：      秒", this);
        text_time->setFont(font);
        text_time->move(150, 210);
        text_time->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        time_label->setFont(font);
        time_label->move(330, 210);
        time_label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
    }
    //-----开始新游戏：重新动态分配游戏界面并关闭其余界面-----
    QPushButton *startbtn = new QPushButton("开始新游戏", this);
    startbtn->resize(200, 80);
    startbtn->move(this->width() * 0.1, this->height() * 0.75);
    connect(startbtn, &QPushButton::clicked, [=]() {
        emit this->newgame();
        gamescene = new game(nullptr, len, wid, num);
        gamescene->show();
        this->hide();
    });
    /*
     * QPushButton * restartbtn = new QPushButton("重新开始这局游戏",this);
     * restartbtn->resize(200,80);
     * restartbtn->move(this->width()*0.375,this->height()*0.75);*/
    //-----返回主菜单：重新生成主菜单并关闭其余界面-----
    QPushButton *backbtn = new QPushButton("返回主菜单", this);
    backbtn->resize(200, 80);
    backbtn->move(this->width() * 0.65, this->height() * 0.75);
    connect(backbtn, &QPushButton::clicked, [=]() {
        emit this->Backtomenu();
        this->close();
        MainWindow *window = new MainWindow();
        window->show();
    });
}
